using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI.WebControls;
using btnet;

/// <summary>
/// Summary description for reports
/// </summary>
public partial class reports : System.Web.UI.Page
{
    protected DataSet ds;
    protected Security security;

    void Page_Load(Object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            String footer_label = null;
            if (Application["custom_footer"] != null)
            {
                footer_label = (String)Application["custom_footer"];
            }
            custom_footer_label.Text = footer_label;
        }

	    Util.do_not_cache(Response);
	
	    security = new Security();
	    security.check_security( HttpContext.Current, Security.ANY_USER_OK);

	    if (security.user.is_admin || security.user.can_use_reports || security.user.can_edit_reports)
	    {
		    //
	    }
	    else
	    {
		    Response.Write ("You are not allowed to use this page.");
		    Response.End();
	    }

	    titl.InnerText = Util.get_setting("AppTitle","BugTracker.NET") + " - "
		    + "reports";

	    string sql = @"
                select
                rp_desc [report],
                case
	                when rp_chart_type = 'pie' then
		                '<a target=''_blank'' href=''view_report.aspx?view=chart&id=' + convert(varchar, rp_id) + '''>pie</a>'
	                when rp_chart_type = 'line' then
		                '<a target=''_blank'' href=''view_report.aspx?view=chart&id=' + convert(varchar, rp_id) + '''>line</a>'
	                when rp_chart_type = 'bar' then
		                '<a target=''_blank'' href=''view_report.aspx?view=chart&id=' + convert(varchar, rp_id) + '''>bar</a>'
	                else
		                '&nbsp;' end [view<br>chart],
                '<a target=''_blank'' href=''view_report.aspx?view=data&id=' + convert(varchar, rp_id) + '''>data</a>' [view<br>data]
                $adm
                from reports order by rp_desc";

	    if (security.user.is_admin || security.user.can_edit_reports)
	    {
		    sql = sql.Replace("$adm", ", " +
			    "'<a href=''edit_report.aspx?id=' + convert(varchar, rp_id) + '''>edit</a>' [edit], " +
			    "'<a href=''delete_report.aspx?id=' + convert(varchar, rp_id) + '''>delete</a>' [delete] ");
	    } else {
		    sql = sql.Replace("$adm", "");
	    }

        ds = btnet.DbUtil.get_dataset(sql);

    }
}